package edu.kit.csl.cratylus.extraction;

import edu.kit.csl.cratylus.datatypes.Word;

/**
 * This writing system utilizes the source word references of target words. As
 * written representations, the content of the aligned source word is used.
 * Note that this may conflict with splitters other than {@link MarxSplitter}
 * since different target words may have the same written representation.
 */
public class RelatedWordWritingSystem implements WritingSystem {

	WritingSystem fallbackWritingSystem;
	
	/**
	 * Sole constructor. Initializes fallback writing system (drop blanks).
	 */
	public RelatedWordWritingSystem() {
		fallbackWritingSystem = new DropBlankWritingSystem();
	}
	
	/**
	 * Returns the content of the related word. If its null, use the fallback
	 * writing system (drop blanks).
	 * 
	 * @param word the word containing a blank separated phoneme string
	 * @return the content of the related word
	 */
	@Override
	public String convert(Word word) {
		Word relWord = word.getRelatedWord();
		if (relWord == null) {
			return fallbackWritingSystem.convert(word);
		}
		return relWord.getContent();
	}

}
